<%
if(isPjax!='true'){
 include("/layouts/platform_top.html"){}
}
%>
<section class="main-content" id="container">

<header class="header navbar bg-white shadow">
    <div class="btn-group tool-button">
        <a class="btn btn-primary navbar-btn btn-sm" href="${base}/platform/sys/conf/add" data-pjax><i class="ti-plus"></i>新建</a>
    </div>
</header>
<div class=panel-body style="padding-top: 50px;">
    <div class="table-responsive no-border">
        <input id="unitid" type="hidden">
        <table class="table table-bordered table-striped mg-t datatable">
            <thead>
                <tr>
                    <th><input id="checkAll" multi="true" type="checkbox" class="select-checkbox-all" /></th>
                    <th>配置项</th>
                    <th>参数值</th>
                    <th>说明</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody></tbody>
        </table>
    </div>
</div>
<div id="dialogDelete" class="modal fade bs-modal-sm" tabindex="-2" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title">删除</h4>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-xs-12">
                        删除后无法恢复，确定删除吗？ <br/>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取 消</button>
                <button id="ok" type="button" class="btn btn-primary" data-loading-text="正在删除...">确 定</button>
            </div>
        </div>
    </div>
</div>
<script language="JavaScript">
    var datatable;
    function initDatatable() {
        datatable = $('.datatable').DataTable({
            "dom": '<"toolbar">lfrtip',
            "searching": false,
            "info":true,
            "lengthChange":false,
            "processing": false,
            "serverSide": true,
            "select": true,
            "ordering": false,
            "language": {
                "url": "${base}/assets/plugins/datatables/cn.json"
            },
            "drawCallback":function () {
                try{$("#checkAll")[0].checked=false;}catch(e){}
            },
            "ajax": {
                "url": "${base}/platform/sys/conf/data",
                "type": "post",
                "data": function (d) {}
            },
            "order": [[1, "asc"]],
            "columns": [
                {"width":"10","sClass": "checkBoxTh","render": function () {return '<input type="checkbox" class="select-checkbox" />';}},
                {"data": "configKey", "bSortable": true},
                {"data": "configValue", "bSortable": true},
                {"data": "note", "bSortable": true},
                {"name":"操作"}
            ],
            "columnDefs": [
                {
                    "render": function (data, type, row) {
                        var s='<a onclick="del(\'' + row.configKey + '\')"  class="btn btn-link btn-xs">删除</a>';
                        if(row.configKey.indexOf('App')>-1){
                            s='';
                        }
                        return '<a href="${base}/platform/sys/conf/edit/' + row.configKey + '/" class="btn btn-link btn-xs" data-pjax>修改</a>' +
                                s;
                    },
                    "targets": -1
                }
            ]
        });
        $("#searchBtn").on('click', function () {
            datatable.ajax.reload();
        });
        datatable.on('click', 'tr:gt(0)', function () {
            if($("#checkAll").length==0){
                $(this).siblings().removeClass("selected");
                $(this).siblings().find(".select-checkbox").prop("checked",false);
            }
            $(this).find(".select-checkbox").prop("checked",true);
            $(this).toggleClass('selected');
        });
        $("#checkAll").on('click',function(){
            var $dataTable=$(this).parent().parent().parent().parent();
            $dataTable.find(".select-checkbox").prop("checked",this.checked);
            if(this.checked){
                $dataTable.find("tbody").find("tr").addClass("selected");
            }else{
                $dataTable.find("tbody").find("tr").removeClass("selected");
            }
        })
    }
    function del(id) {
        debugger;
        var dialog = $("#dialogDelete");
        dialog.modal("show");
        dialog.find("#ok").unbind("click");
        dialog.find("#ok").bind("click", function (event) {
            var btn = $(this);
            btn.button("loading");
            $.post("${base}/platform/sys/conf/delete/" + id, {}, function (data) {
                if (data.code == 0) {
                    datatable.ajax.reload(null,false);
                } else {
                    Toast.error(data.msg);
                }
                //重置按钮状态，关闭提示框
                btn.button("reset");
                dialog.modal("hide");
            }, "json");
        });
    }
    $(function () {
        initDatatable();
    });
</script>
</section>
<%
if(isPjax!='true'){
include("/layouts/platform_bottom.html"){}
}
%>